<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <h3>在输入框中尝试输入字母 a:</h3>
        <form action=""> 
        输入姓名: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
        </form>
        <p>提示信息: <span id="txtHint"></span></p>

    <script>
       
        //   var xml;
        //   if(window.XMLHttpRequest){ //ie6以外的
        //        xml = new XMLHttpRequest();
        //   }else{
        //       xml = new ActiveXObject('Microsoft.XMLHTTP');//ie5,ie6
        //   }

        //   xml.open('get','./test.php',true)
        //   xml.send()

        //   xml.onreadystatechange = function(){
        //       if(xml.readyState == 4 && xml.status ==200){
        //           console.log(xml.responseText)
        //       }
        //   }


    function showHint(str)
{
  var xmlhttp;
  if (str.length==0)
  { 
    document.getElementById("txtHint").innerHTML="";
    return;
  }
  if (window.XMLHttpRequest)
  {
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp=new XMLHttpRequest();
  }
  else
  {
    // IE6, IE5 浏览器执行代码
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","./test.php?q="+str,true);
  xmlhttp.send();
}
    </script>
   
 

   <!----------------------------josnp跨域--------------------------->

   <script>
      function train(res){
           console.log(res)
      }
     
     function handleResponse(res){
         console.log(res)
     }
   </script>

<script src="https://api.douban.com/v2/book/search?q=javascript&count=1&callback=handleResponse"></script>
<script src="./car.js?cb = train"></script>
</body>
</html>